package com.itheima.info.manager.system.service;

import com.itheima.info.manager.system.dao.TeacherDao;
import com.itheima.info.manager.system.domain.Teacher;

/*
老师的 业务处理类
判断
老师的
增
删
改
查

 */
public class TeacherService {
    private TeacherDao teacherDao = new TeacherDao();

    //增
    public boolean addTeacher(Teacher teacher) {
        return teacherDao.addTeacher(teacher);
    }

    //删
    public void deleteTeacher(String sid) {
        teacherDao.deleteTeacher(sid);
    }

    //改
    public void updateTeacher(String sid, Teacher teacher) {
        teacherDao.updateTeacher(sid, teacher);
    }

    //查
    public Teacher[] findAllTeachers() {
        Teacher[] teachers = teacherDao.findAllTeachers();
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if (teacher != null) {
                return teachers;
            }
        }
        return null;
    }

    //判断 老师是否存在
    public boolean isExists(String sid) {
        Teacher[] teachers = teacherDao.findAllTeachers();
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if (teacher != null && teacher.getSid().equals(sid)) {
                return true;
            }
        }
        return false;
    }
}
